<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商品分类管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var path = "<%=path%>";
		
		$(document).ready(function(){
			
		    $('#mgrTable').treegrid(); 
		});
		
		var url;
		
		function add(){
			
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				window.location = path+"/category/init.do?type=add&categoryId="+selected.id;
			}else{
				alertBox("请选择父商品分类节点！");
			}
		}
		
		function edit(){
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				window.location = path+"/category/init.do?type=edit&categoryId="+selected.id;
			}else{
				alertBox("请选择需要编辑的商品分类！");
			}
		}
		
		function remove(){
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	url = path +"/category/delete.do?categoryId="+selected.id+"&t="+new Date().getTime();
						$.ajax({
						  url: url,
						  success: function(data) {
							   if(data == "1")
							   {
									$('#mgrTable').treegrid('reload');
									alertBox("操作成功！");
							   } else {
									alertBox("操作失败！");
							   }
						  }
						});
				    }
				    	
				    return true; //close
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				alertBox("请选择需要删除的商品分类！");
			}
		}
		
		function sendMsgFormatter(value,rec){
          	if(value == "0"){
				return "是";
			}
			return "否";
        }
		
		function pcountFormatter(value,rec){
          	if(value == "-1"){
				return "无";
			}
			return value;
        }
		
		function refresh(){
			$('#mgrTable').treegrid('reload');
		}
		
	</script>

  </head>
  
  <body>
    <div class="right">
		<h1><b>商品分类管理</b><span><img src="<%=basePath %>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
		<div class="ri_main">
			<div id="toolbar">
				<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				<a href="javascript:void(0);" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit">编辑</a>
				<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
		 	<table id="mgrTable" toolbar="#toolbar" idField="id" treeField="name" 
		 		url="category/list.do" singleSelect="true" rownumbers="true" animate="true" height="200">
		 		<thead>
					<tr>
						<th field="name" width="200" frozen="true">名称</th>
						<!--
						<th field="url" width="150">路径</th>
						-->
						<th field="description" width="150">描述</th>
						<th field="sendMsg" width="120" formatter="sendMsgFormatter">是否发送购物信息</th>
						<th field="pcount" width="70" formatter="pcountFormatter">限购买数量</th>
						<!--
						<th field="layerOrder" width="100">排序编号</th>
						-->
					</tr>
				</thead>
		 	</table>  
		</div>
	</div>
	
  </body>
</html>
